<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Yjb extends CI_Controller {
	
	private $tab ='borrow';
	
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	
	function borrowlist(){
		$data['where']['fstatus'] = intval($this->input->get('fstatus'));
		$data['where']['title'] = trim($this->input->get('title'));
		$data['where']['username'] = trim($this->input->get('username'));
		$data['per_page'] = intval($this->input->get('per_page'));
		$data['page_size'] = sys_admin_LIST_PAGE_SIZE;
		$this->load->model('Yjb_model');
		$vdata = $this->Yjb_model->get_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/yjb/borrowlist/?title='.$title.'&username='.$username.'&fstatus='.$fstatus;
		$config['total_rows'] = $vdata['count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['where'] = $data['where'];
		
		$vdata['tab'] = $this->tab;
		
		if($data['where']['fstatus'] == 1){
			$sub = 'yjb_first';
		}else{
			$sub = 'yjb_full';
		}
		$vdata['sub'] = $sub;
		
		$this->load->view('/sys_admin/borrow/yjb_list', $vdata);
		
	}
	
	function verify($id=0){
		$id = intval($id);
		$this->load->model('Yjb_model');
		$info = $this->Yjb_model->get_by_id($id);
		$vdata['borrow']=$info;
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'yjb_first';
		
		$this->load->view('/sys_admin/borrow/yjb_view',$vdata);
	}
	
	function edit(){
		$admin = $this->session->userdata('admin_user');
		$id = intval($this->input->post('id'));
		
		$timeLimitArr = $this->input->post('time_limit');
		if (empty($timeLimitArr)){
			$this->js->alert('请选择期限');
			exit;
		}
		$aprList = array();
		foreach ($timeLimitArr as $timeLimit){
			if (!in_array($timeLimit, array(7,15,20,30))){
				$this->js->alert('期限错误');
				exit;
			}
			$tmpApr = round($this->input->post('apr'.$timeLimit),2);
			//$tmpAward = round($this->input->post('award'.$timeLimit),2);
			if ($tmpApr<=0 || $tmpApr>24){
				$this->js->alert('请填写有效利率');
				exit;
			}
			
			$aprList[] = array(
				'time_limit' => $timeLimit,
				'apr' => $tmpApr,
				'award' => 0
			);
		}
		
		$fstatus = intval($this->input->post('fstatus'));
		
		//自动审核时间 ----start
		$auto_verify_time_post 			= $this->input->post("auto_verify_time");
		$min = date('i',strtotime($auto_verify_time_post)); 
		if($min%10 == 0){
			$auto_verify_time = strtotime($auto_verify_time_post);
		}else{
			$m = round($min/10)*10;
			$new_time = date('Y-m-d H',strtotime($auto_verify_time_post));
			$auto_verify_time = strtotime($new_time.':'.$m);
		}		
		//自动审核时间 ----end
		
		$setArr = array(
			'title' => trim($this->input->post('title')),
			'apr_list' => json_encode($aprList),
			'account' => round($this->input->post("account"),2),
			'lowest_account' => round($this->input->post("lowest_account"),2),
			'most_account' => round($this->input->post("most_account"),2),
			'one_account' => round($this->input->post("one_account"),2),
			'content' => $this->input->post("content"),
			
			'fstatus' => $fstatus,
			'verify_user' => $admin['user_id'],
			'verify_time' => time(),
			'auto_verify_time' => $auto_verify_time,
			'verify_remark' => $this->input->post('verify_remark')
		);
		
		$where=array('id'=>$id);
		$this->load->model('Yjb_model');
		$res = $this->Yjb_model->update($setArr,$where);
		if ($res) {
			if ($fstatus==2){
				$this->Yjb_model->yjb_auto_tender($id);
			}
			$index_yjb_key = 'rsh_index_yjb';
			$this->mycache->delete($index_yjb_key);
			$this->js->alert('操作成功');
			$this->js->go('/sys_admin/yjb/borrowlist.html?fstatus=1');
		}else{
			$this->js->alert('操作失败');
		}
		exit;
	}
	
	/**
	 * 投标记录
	 */
	function tenderlist(){
		//echo '暂无';
		$data['fstatus'] = intval($this->input->get('fstatus'));
		$data['username'] = trim($this->input->get('username'));
		$data['strtime'] = trim($this->input->get('strtime'));
		$data['endtime'] = trim($this->input->get('endtime'));
		$data['time_limit_day'] = intval($this->input->get('time_limit_day'));
		$data['is_self'] = isset($_GET['is_self']) ? $this->input->get('is_self') : -1;
		$data['per_page'] = intval($this->input->get('per_page'));
		$data['page_size'] = sys_admin_LIST_PAGE_SIZE;
		$data['order'] = 'add_time';
		$this->load->model('Yjb_model');
		$ret = $this->Yjb_model->tender_list($data);
		
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/yjb/tenderlist.html?username='.$data['username'].'&fstatus='.$data['fstatus'].'&is_self='.$data['is_self'].'&strtime='.$data['strtime'].'&endtime='.$data['endtime'].'&time_limit_day='.$data['time_limit_day'];
		$config['total_rows'] = $ret['count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$data['list'] = $ret['list'];
		$data['count'] = $ret['count'];
		$data['total_money'] = $ret['total_money'];
		$data['total_people'] = $ret['total_people'];
		
		$data['tab'] = $this->tab;
		$data['sub'] = 'yjb_tender_record';
		
		$this->load->view('/sys_admin/borrow/yjb_tender_list', $data);
		
	}
	
	/**
	 * 回款记录
	 */
	function repaylist(){
		$data['fstatus'] = intval($this->input->get('fstatus'));
		$data['username'] = trim($this->input->get('username'));
		$data['r_strtime'] = trim($this->input->get('r_strtime'));
		$data['r_endtime'] = trim($this->input->get('r_endtime'));
		$data['time_limit_day'] = intval($this->input->get('time_limit_day'));
		$data['is_self'] = isset($_GET['is_self']) ? $this->input->get('is_self') : -1;
		$data['per_page'] = intval($this->input->get('per_page'));
		$data['page_size'] = sys_admin_LIST_PAGE_SIZE;
		$data['order'] = 'repay_time';
		$this->load->model('Yjb_model');
		$ret = $this->Yjb_model->tender_list($data);
		
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/yjb/repaylist.html?username='.$data['username'].'&fstatus='.$data['fstatus'].'&is_self='.$data['is_self'].'&r_strtime='.$data['r_strtime'].'&r_endtime='.$data['r_endtime'].'&time_limit_day='.$data['time_limit_day'];
		$config['total_rows'] = $ret['count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$data['list'] = $ret['list'];
		$data['count'] = $ret['count'];
		$data['total_money'] = $ret['total_money'];
		$data['total_repay'] = $ret['total_repay'];
		$data['total_people'] = $ret['total_people'];
		
		$data['tab'] = 'account';
		$data['sub'] = 'yjb_received';
		
		$this->load->view('/sys_admin/borrow/yjb_repay_list', $data);
	}
	
	
	function borrow_yjb_check(){
		$admin = $this->session->userdata('admin_user');
		$id = intval($this->input->post('id'));
		
		$timeLimitArr = $this->input->post('time_limit');
		if (empty($timeLimitArr)){
			echo '请选择期限';
			exit;
		}
		$aprList = array();
		foreach ($timeLimitArr as $timeLimit){
			if (!in_array($timeLimit, array(7,15,20,30))){
				echo '期限错误';
				exit;
			}
			$tmpApr = round($this->input->post('apr'.$timeLimit),2);
			//$tmpAward = round($this->input->post('award'.$timeLimit),2);
			if ($tmpApr<=0 || $tmpApr>24){
				echo '请填写有效利率';
				exit;
			}
			
			$aprList[] = array(
				'time_limit' => $timeLimit,
				'apr' => $tmpApr,
				'award' => 0
			);
		}
		
		$fstatus = intval($this->input->post('fstatus'));
		
		//自动审核时间 ----start
		$auto_verify_time_post 			= $this->input->post("auto_verify_time");
		$min = date('i',strtotime($auto_verify_time_post)); 
		if($min%10 == 0){
			$auto_verify_time = strtotime($auto_verify_time_post);
		}else{
			$m = round($min/10)*10;
			$new_time = date('Y-m-d H',strtotime($auto_verify_time_post));
			$auto_verify_time = strtotime($new_time.':'.$m);
		}		
		//自动审核时间 ----end
		
		$setArr = array(
			'title' => trim($this->input->post('title')),
			'apr_list' => json_encode($aprList),
			'account' => round($this->input->post("account"),2),
			'lowest_account' => round($this->input->post("lowest_account"),2),
			'most_account' => round($this->input->post("most_account"),2),
			'one_account' => round($this->input->post("one_account"),2),
			'content' => $this->input->post("content"),
			'is_check' => 1,
			'auto_verify_time' => $auto_verify_time,
		);
		
		$where=array('id'=>$id);
		$this->load->model('Yjb_model');
		$res = $this->Yjb_model->update($setArr,$where);
		if ($res) {
			$this->load->model('log_model');
			$admin = $this->session->userdata('admin_user');
			$username = $admin['username'];
			$this->log_model->add_log('[易居宝发标待审数据检查][借款标][ID=='.$id.'] ['.$username.'已检查]');
			echo $res;
		}else{
			echo 0;
		}
		exit;
	}
	
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Yjb extends CI_Controller {
    
	private $tab ='borrow';
	
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	
	function borrowlist(){
		$data['where']['fstatus'] = intval($this->input->get('fstatus'));
		$data['where']['title'] = trim($this->input->get('title'));
		$data['where']['username'] = trim($this->input->get('username'));
		$data['per_page'] = intval($this->input->get('per_page'));
		$data['page_size'] = sys_admin_LIST_PAGE_SIZE;
		$this->load->model('Yjb_model');
		$vdata = $this->Yjb_model->get_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/yjb/borrowlist/?title='.$title.'&username='.$username.'&fstatus='.$fstatus;
		$config['total_rows'] = $vdata['count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['where'] = $data['where'];
		
		$vdata['tab'] = $this->tab;
		
		if($data['where']['fstatus'] == 1){
			$sub = 'yjb_first';
		}else{
			$sub = 'yjb_full';
		}
		$vdata['sub'] = $sub;
		
		$this->load->view('/sys_admin/borrow/yjb_list', $vdata);
		
	}
	
	function verify($id=0){
		$id = intval($id);
		$this->load->model('Yjb_model');
		$info = $this->Yjb_model->get_by_id($id);
		$vdata['borrow']=$info;
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'yjb_first';
		
		$this->load->view('/sys_admin/borrow/yjb_view',$vdata);
	}
	
	function edit(){
		$admin = $this->session->userdata('admin_user');
		$id = intval($this->input->post('id'));
		
		$timeLimitArr = $this->input->post('time_limit');
		if (empty($timeLimitArr)){
			$this->js->alert('请选择期限');
			exit;
		}
		$aprList = array();
		foreach ($timeLimitArr as $timeLimit){
			if (!in_array($timeLimit, array(7,15,20,30))){
				$this->js->alert('期限错误');
				exit;
			}
			$tmpApr = round($this->input->post('apr'.$timeLimit),2);
			//$tmpAward = round($this->input->post('award'.$timeLimit),2);
			if ($tmpApr<=0 || $tmpApr>24){
				$this->js->alert('请填写有效利率');
				exit;
			}
			
			$aprList[] = array(
				'time_limit' => $timeLimit,
				'apr' => $tmpApr,
				'award' => 0
			);
		}
		
		$fstatus = intval($this->input->post('fstatus'));
		
		//自动审核时间 ----start
		$auto_verify_time_post 			= $this->input->post("auto_verify_time");
		$min = date('i',strtotime($auto_verify_time_post)); 
		if($min%10 == 0){
			$auto_verify_time = strtotime($auto_verify_time_post);
		}else{
			$m = round($min/10)*10;
			$new_time = date('Y-m-d H',strtotime($auto_verify_time_post));
			$auto_verify_time = strtotime($new_time.':'.$m);
		}		
		//自动审核时间 ----end
		
		$setArr = array(
			'title' => trim($this->input->post('title')),
			'apr_list' => json_encode($aprList),
			'account' => round($this->input->post("account"),2),
			'lowest_account' => round($this->input->post("lowest_account"),2),
			'most_account' => round($this->input->post("most_account"),2),
			'one_account' => round($this->input->post("one_account"),2),
			'content' => $this->input->post("content"),
			
			'fstatus' => $fstatus,
			'verify_user' => $admin['user_id'],
			'verify_time' => time(),
			'auto_verify_time' => $auto_verify_time,
			'verify_remark' => $this->input->post('verify_remark')
		);
		
		$where=array('id'=>$id);
		$this->load->model('Yjb_model');
		$res = $this->Yjb_model->update($setArr,$where);
		if ($res) {
			if ($fstatus==2){
				$this->Yjb_model->yjb_auto_tender($id);
			}
			$index_yjb_key = 'rsh_index_yjb';
			$this->mycache->delete($index_yjb_key);
			$this->js->alert('操作成功');
			$this->js->go('/sys_admin/yjb/borrowlist.html?fstatus=1');
		}else{
			$this->js->alert('操作失败');
		}
		exit;
	}
	
	/**
	 * 投标记录
	 */
	function tenderlist(){
		//echo '暂无';
		$data['fstatus'] = intval($this->input->get('fstatus'));
		$data['username'] = trim($this->input->get('username'));
		$data['strtime'] = trim($this->input->get('strtime'));
		$data['endtime'] = trim($this->input->get('endtime'));
		$data['time_limit_day'] = intval($this->input->get('time_limit_day'));
		$data['is_self'] = isset($_GET['is_self']) ? $this->input->get('is_self') : -1;
		$data['per_page'] = intval($this->input->get('per_page'));
		$data['page_size'] = sys_admin_LIST_PAGE_SIZE;
		$data['order'] = 'add_time';
		$this->load->model('Yjb_model');
		$ret = $this->Yjb_model->tender_list($data);
		
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/yjb/tenderlist.html?username='.$data['username'].'&fstatus='.$data['fstatus'].'&is_self='.$data['is_self'].'&strtime='.$data['strtime'].'&endtime='.$data['endtime'].'&time_limit_day='.$data['time_limit_day'];
		$config['total_rows'] = $ret['count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$data['list'] = $ret['list'];
		$data['count'] = $ret['count'];
		$data['total_money'] = $ret['total_money'];
		$data['total_people'] = $ret['total_people'];
		
		$data['tab'] = $this->tab;
		$data['sub'] = 'yjb_tender_record';
		
		$this->load->view('/sys_admin/borrow/yjb_tender_list', $data);
		
	}
	
	/**
	 * 回款记录
	 */
	function repaylist(){
		$data['fstatus'] = intval($this->input->get('fstatus'));
		$data['username'] = trim($this->input->get('username'));
		$data['r_strtime'] = trim($this->input->get('r_strtime'));
		$data['r_endtime'] = trim($this->input->get('r_endtime'));
		$data['time_limit_day'] = intval($this->input->get('time_limit_day'));
		$data['is_self'] = isset($_GET['is_self']) ? $this->input->get('is_self') : -1;
		$data['per_page'] = intval($this->input->get('per_page'));
		$data['page_size'] = sys_admin_LIST_PAGE_SIZE;
		$data['order'] = 'repay_time';
		$this->load->model('Yjb_model');
		$ret = $this->Yjb_model->tender_list($data);
		
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/yjb/repaylist.html?username='.$data['username'].'&fstatus='.$data['fstatus'].'&is_self='.$data['is_self'].'&r_strtime='.$data['r_strtime'].'&r_endtime='.$data['r_endtime'].'&time_limit_day='.$data['time_limit_day'];
		$config['total_rows'] = $ret['count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$data['list'] = $ret['list'];
		$data['count'] = $ret['count'];
		$data['total_money'] = $ret['total_money'];
		$data['total_repay'] = $ret['total_repay'];
		$data['total_people'] = $ret['total_people'];
		
		$data['tab'] = 'account';
		$data['sub'] = 'yjb_received';
		
		$this->load->view('/sys_admin/borrow/yjb_repay_list', $data);
	}
	
	
	function borrow_yjb_check(){
		$admin = $this->session->userdata('admin_user');
		$id = intval($this->input->post('id'));
		
		$timeLimitArr = $this->input->post('time_limit');
		if (empty($timeLimitArr)){
			echo '请选择期限';
			exit;
		}
		$aprList = array();
		foreach ($timeLimitArr as $timeLimit){
			if (!in_array($timeLimit, array(7,15,20,30))){
				echo '期限错误';
				exit;
			}
			$tmpApr = round($this->input->post('apr'.$timeLimit),2);
			//$tmpAward = round($this->input->post('award'.$timeLimit),2);
			if ($tmpApr<=0 || $tmpApr>24){
				echo '请填写有效利率';
				exit;
			}
			
			$aprList[] = array(
				'time_limit' => $timeLimit,
				'apr' => $tmpApr,
				'award' => 0
			);
		}
		
		$fstatus = intval($this->input->post('fstatus'));
		
		//自动审核时间 ----start
		$auto_verify_time_post 			= $this->input->post("auto_verify_time");
		$min = date('i',strtotime($auto_verify_time_post)); 
		if($min%10 == 0){
			$auto_verify_time = strtotime($auto_verify_time_post);
		}else{
			$m = round($min/10)*10;
			$new_time = date('Y-m-d H',strtotime($auto_verify_time_post));
			$auto_verify_time = strtotime($new_time.':'.$m);
		}		
		//自动审核时间 ----end
		
		$setArr = array(
			'title' => trim($this->input->post('title')),
			'apr_list' => json_encode($aprList),
			'account' => round($this->input->post("account"),2),
			'lowest_account' => round($this->input->post("lowest_account"),2),
			'most_account' => round($this->input->post("most_account"),2),
			'one_account' => round($this->input->post("one_account"),2),
			'content' => $this->input->post("content"),
			'is_check' => 1,
			'auto_verify_time' => $auto_verify_time,
		);
		
		$where=array('id'=>$id);
		$this->load->model('Yjb_model');
		$res = $this->Yjb_model->update($setArr,$where);
		if ($res) {
			$this->load->model('log_model');
			$admin = $this->session->userdata('admin_user');
			$username = $admin['username'];
			$this->log_model->add_log('[易居宝发标待审数据检查][借款标][ID=='.$id.'] ['.$username.'已检查]');
			echo $res;
		}else{
			echo 0;
		}
		exit;
	}
	
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}